package com.alan.product.issue.gc;

import com.alan.product.issue.entity.Player;
import com.alan.product.issue.entity.Room;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadLocalRandom;

/**
 * system.gc()测试
 * 参数：-XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:./gclogs.log
 * 禁用：-XX:+DisableExplicitGC
 * 其他：-XX:+UseConcMarkSweepGC -XX:+ExplicitGCInvokesConcurrent
 *                              -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
 */
@RestController
public class SystemGcTestController {

    @PostMapping("system.gc")
    public String systemGc() {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        // 大对象
        Player player = new Player(random.nextLong());
        player.setStatus(1);

        player = null;

        // 让gc赶紧把player这个大对象给清理掉
        System.gc();

        // 其它逻辑
        Room room = new Room();
        room.setId(1L);

        return "success";
    }

}
